ActiveReports 9 > ActiveReports User Guide > Concepts > Exporting > Rendering Extensions > Rendering to Word |
MS Word is one of the formats to which you can export ActiveReports from the Viewer. You can use the WordRenderingExtension to render your report in Microsoft® Word 2003 and 2007 formats.
In order to render your report in MS Word, add reference to the following assemblies in the project:
The following steps provide an example of rendering a report in the Word format.
Visual Basic.NET code. Paste INSIDE the Form Load event. |
Copy Code
|
---|---|
' Provide the page report you want to render. Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo("C:\Sample_PageReport.rdlx")) Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report) ' Create a output directory Dim outputDirectory As New System.IO.DirectoryInfo("C:\MyWord") outputDirectory.Create() ' Provide settings for your rendering output. Dim wordSetting As New GrapeCity.ActiveReports.Export.Word.Page.Settings() Dim setting As GrapeCity.ActiveReports.Extensibility.Rendering.ISettings = wordSetting ' Set the rendering extension and render the report. Dim wordRenderingExtension As New GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension() Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name)) reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting) |
C# code. Paste INSIDE the Form Load event. |
Copy Code
|
---|---|
// Provide the page report you want to render. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(@"C:\Sample_PageReport.rdlx")); GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report); // Create a output directory System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyWord"); outputDirectory.Create(); // Provide settings for your rendering output. GrapeCity.ActiveReports.Export.Word.Page.Settings wordSetting = new GrapeCity.ActiveReports.Export.Word.Page.Settings(); GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = wordSetting; //Set the rendering extension and render the report. GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension wordRenderingExtension = new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension(); GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name)); reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting); |
ActiveReports offers several options to control how reports render to Microsoft® Word.
Property | Description |
---|---|
Author | Enter the name of the author to appear in the File Properties dialog of the Microsoft® Word application on the Summary tab in the Author field. |
BaseUrl | Enter a base URL for any relative hyperlinks used in the report. This value appears in the File Properties dialog of the Microsoft® Word application on the Summary tab in the Hyperlink base field. |
Generator | Set the identity of the document generator in a meta-data file stamp. The default value is "Created using ActiveReports." |
PageHeight | Enter a value in inches (i.e. 11 in) to set the height of the report's pages. This value overrides the report's original settings. |
PageWidth | Enter a value in inches (i.e. 8.5 in) to set the width of the report's pages. This value overrides the report's original settings. |
Title | Enter the document’s title. This value appears in the File Properties dialog of the Microsoft® Word application on the Summary tab in the Title field. |
UseMhtOutput | Set True or False value to indicate whether Mht output is to be used for the resultant Word document or not. |
Although background colors for controls export to Word documents, background colors for sections such as Body and Page Header or Footer do not.
Reports rendered in a Word format supports both Bookmarks and Hyperlinks. However, if visibility toggling (like in a drill-down report) is essential to your report, it is recommended to use the HTML rendering extension. And If a Document map is essential to your report, it is recommended to use the PDF rendering extension.